﻿using System.ComponentModel;
using System.Windows.Media;

namespace System.Windows.Controls
{
    /// <summary>
    /// Represent a text label to be displayed on the gauge
    /// </summary>
    public class GaugeCaption : FrameworkContentElement,INotifyPropertyChanged
    {
        private static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof (string),
                                                                                              typeof(GaugeCaption),
                                                                                              new PropertyMetadata(
                                                                                                  OnPropertyChanged));

        private static readonly DependencyProperty SizeProperty = DependencyProperty.Register("Size", typeof (int),
                                                                                              typeof(GaugeCaption),
                                                                                              new PropertyMetadata(
                                                                                                  OnPropertyChanged));

        private static readonly DependencyProperty ForegroundProperty = DependencyProperty.Register("Foreground",
                                                                                                    typeof (Brush),
                                                                                                    typeof(GaugeCaption),
                                                                                                    new PropertyMetadata
                                                                                                        (OnPropertyChanged));

        private static readonly DependencyProperty YProperty = DependencyProperty.Register("Y", typeof (double),
                                                                                           typeof (GaugeCaption),
                                                                                           new PropertyMetadata(
                                                                                               OnPropertyChanged));

        private static readonly DependencyProperty XProperty = DependencyProperty.Register("X", typeof (double),
                                                                                           typeof (GaugeCaption),
                                                                                           new PropertyMetadata(
                                                                                               OnPropertyChanged));
        /// <summary>
        /// The actual text to display
        /// </summary>
        public string Text
        {
            get { return (string) GetValue(TextProperty); }
            set { SetValue(TextProperty, value); }
        }
        /// <summary>
        /// The font size
        /// </summary>
        public int Size
        {
            get { return (int) GetValue(SizeProperty); }
            set { SetValue(SizeProperty, value); }
        }
        /// <summary>
        /// The text foreground color
        /// </summary>
        public Brush Foreground
        {
            get { return (Brush) GetValue(ForegroundProperty); }
            set { SetValue(ForegroundProperty, value); }
        }
        /// <summary>
        /// The Top location of the text
        /// </summary>
        public double Y
        {
            get { return (double) GetValue(YProperty); }
            set { SetValue(YProperty, value); }
        }
        /// <summary>
        /// The left location of the text
        /// </summary>
        public double X
        {
            get { return (double) GetValue(XProperty); }
            set { SetValue(XProperty, value); }
        }

        public override string ToString()
        {
            return string.Format("Caption:{0}//{1}.{2}", this.X, this.Y, this.Text);
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged = (s, p) => { };

        #endregion

        private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var caption = (GaugeCaption) d;
            caption.PropertyChanged(caption, new PropertyChangedEventArgs(e.Property.Name));
            
        }
    }
}